package leetcode.editor.cn;

import java.util.HashSet;
import java.util.Set;

public class P349IntersectionOfTwoArrays {
    public static void main(String[] args) {
        Solution solution = new P349IntersectionOfTwoArrays().new Solution();
        solution.intersection(new int[]{1, 2, 2, 1}, new int[]{2, 2});
        
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> hash1 = new HashSet<>();
        Set<Integer> hash2 = new HashSet<>();
        for (int i : nums1) {
            hash1.add(i);
        }
        for (int i : nums2) {
            hash2.add(i);
        }
        hash1.retainAll(hash2);
        int[] result = new int[hash1.size()];
        int index = 0;
        for (Integer i : hash1) {
            result[index++] = i;
        }
        return result;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}